package com.fzdy.product.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "t_order")
@Data
@NoArgsConstructor
public class Order {
    @Id
    @Column(name = "id")
    private Integer id;
    @Column(name = "order_id")
    private String orderId;
    @Column(name = "name")
    private String name;
    @Column(name = "device_num")
    private Integer deviceNum;
    @Column(name = "begin_sn")
    private String beginSn;
    @Column(name = "create_date")
    private Date createDate;
    @Column(name = "soft_version")
    private String softVersion;
    @Column(name = "firmware_version")
    private String firmwareVersion;
    @Column(name = "endtime")
    private Date endtime;
    @Column(name = "product_type")
    private Integer productType;
    @Column(name = "process_scheme_id", insertable = false, updatable = false)
    private Integer processSchemeId;
    @Column(name = "customer")
    private String customer;
    @Transient
    private Integer newNum;

    @ManyToOne
    @JoinColumn(name = "product_type", referencedColumnName = "id", foreignKey = @ForeignKey(name = "t_order_ibfk_1"),
            insertable = false, updatable = false)
    private ProductType type;

    @ManyToOne
    @JoinColumn(name = "process_scheme_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "t_order_ibfk_2"))
    private ProcessScheme processScheme;


    public Order(String orderId, String name, String customer, String typeName) {
        this.orderId = orderId;
        this.name = name;
        this.customer = customer;
        ProductType type = new ProductType();
        type.setName(typeName);
        this.type = type;
    }

    public Order(String orderId, String name, Integer deviceNum,String beginSn,String softVersion, String firmwareVersion, Integer productType, String schemeName, String schemeDemo, String customer) {
        this.orderId = orderId;
        this.name = name;
        this.deviceNum = deviceNum;
        this.beginSn=beginSn;
        this.createDate = new Date();
        this.softVersion = softVersion;
        this.firmwareVersion = firmwareVersion;
        this.productType = productType;
        ProcessScheme processScheme1 = new ProcessScheme();
        processScheme1.setName(schemeName);
        processScheme1.setDemo(schemeDemo);
        this.processScheme = processScheme1;
        this.customer = customer;
    }
}
